<?php
declare (strict_types = 1);

namespace app\middleware;

use app\model\admin\LoginState;

class JwtAuthForAdmin
{
    /**
     * 登录校验中间件
     * 使用方法：(在控制器配置)
     * protected $middleware = [\app\middleware\JwtAuthForApi::class];
     * protected $middleware = [\app\middleware\JwtAuthForApi::class => ['except'=>['login','regist']]];
     * 详细说明: https://www.kancloud.cn/manual/thinkphp6_0/1037515
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $msgInfo =LoginState::checkJwt('admin');
        if (!$msgInfo['success']) {
            return json($msgInfo);
        }
        return $next($request);
    }
}
